package com.huatai.datacenter.controller.datamodel;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.huatai.common.api.R;
import com.huatai.datacenter.entity.datamodel.DataModelApplyEntity;
import com.huatai.datacenter.service.DataModelApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;


/**
 * @author gusiyi
 * @version 1.0
 * @className DataModelApplyController
 * @description 描述：
 * @date 2023/5/26 17:01
 */
@RestController
@RequestMapping("/dataModel/apply")
@Api(value = "数据模型应用",tags = "数据模型应用")
public class DataModelApplyController {

	@Autowired
	private DataModelApplyService dataModelApplyService;

	@RequestMapping("/getList")
	@ApiOperation("获取数据模型应用清册")
	@ApiOperationSupport(order = 1, includeParameters = {
		"dataModelApplyEntity.pageIndex",
		"dataModelApplyEntity.pageSize",
		"dataModelApplyEntity.dataModelName",
		"dataModelApplyEntity.applyTypeNum"
	})
	public R<Page<DataModelApplyEntity>> getList(@RequestBody DataModelApplyEntity dataModelApplyEntity){
		Page<DataModelApplyEntity> dataModelApplyServiceList = dataModelApplyService.getDataModelApplyList(dataModelApplyEntity);
		return R.data(dataModelApplyServiceList,"获取数据模型应用清册成功");
	}

	@RequestMapping("/bindApply")
	@ApiOperation(value = "(后台使用)数据模型与应用（数据源）绑定",notes = "后台使用通过DataModelApplyService调用")
	@ApiOperationSupport(order = 2, includeParameters = {
		"dataModelApplyEntity.dataModelId",
		"dataModelApplyEntity.dataModelName",
		"dataModelApplyEntity.applyId",
		"dataModelApplyEntity.applyName",
		"dataModelApplyEntity.applyTypeName"
	})
	public R<DataModelApplyEntity> saveDataModelApplyInstance(@Valid @RequestBody DataModelApplyEntity dataModelApplyEntity){
		boolean success = dataModelApplyService.saveDataModelApplyInstance(
				dataModelApplyEntity.getDataModelId(),
				dataModelApplyEntity.getDataModelName(),
				dataModelApplyEntity.getApplyId(),
				dataModelApplyEntity.getApplyName(),
				dataModelApplyEntity.getApplyTypeName());
		return R.status(success);
	}

	@RequestMapping("/deleteApplyByApplyContentIds")
	@ApiOperation(value = "(后台使用)根据应用内容id删除模型应用",notes = "后台使用通过DataModelApplyService调用")
	@ApiOperationSupport(order = 2, includeParameters = {
		"dataModelApplyEntity.applyId"
	})
	public R<DataModelApplyEntity> deleteApplyContentByApplyId(@Valid @RequestBody List<Long> deleteIds){
		boolean success = dataModelApplyService.deleteApplyContentByApplyId(deleteIds);
		return R.status(success);
	}
}
